package Hystrix;

import com.netflix.hystrix.HystrixCommand;
import com.netflix.hystrix.HystrixCommandGroupKey;

import java.util.Observable;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.Future;

/**
 * Created with IDEA
 * author:Yhk
 * Date:2019/6/19
 * Time:1:41 PM
 */
public class CommandHelloWorld extends HystrixCommand<String> {
    private final String name;

    public CommandHelloWorld(String name) {
        super(HystrixCommandGroupKey.Factory.asKey("ExampleGroup")); //必须
        this.name = name;
    }

    @Override
    protected String run() throws Exception {
        return "Hello " + name + "!";
    }

    public static void main(String[] args) throws ExecutionException, InterruptedException {
//        String s = new CommandHelloWorld("Bob").execute();
//        System.out.println(s);
        Future<String> fs = new CommandHelloWorld("World").queue();
        System.out.println(fs.isDone());
        String s = fs.get();
        System.out.println(s);
        System.out.println(fs.isDone());

    }
}
